<%@ WebHandler Language="C#" Class="UEditorHandler" %>

using System;
using System.Web;
using System.IO;
using System.Collections;
using Newtonsoft.Json;
using UEditor;
    public class UEditorHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            UEHandler action = null;
            switch (context.Request["action"])
            {
                case "config":
                    action = new ConfigHandler(context);
                    break;
                case "uploadimage":
                    bool iswatermark = context.Request["iswatermark"] == null ? false : context.Request["iswatermark"] == "true";
                    action = new UploadHandler(context, new UploadConfig()
                    {
                        AllowExtensions = UEConfig.GetStringList("imageAllowFiles"),
                        PathFormat = UEConfig.GetString("imagePathFormat") + "root/{yyyy}_{mm}/{time}{rand:6}",
                        SizeLimit = UEConfig.GetInt("imageMaxSize"),
                        UploadFieldName = UEConfig.GetString("imageFieldName"),
                        IsWaterMark=iswatermark
                    });
                    break;
                case "uploadscrawl":
                    action = new UploadHandler(context, new UploadConfig()
                    {
                        AllowExtensions = new string[] { ".png" },
                        PathFormat = UEConfig.GetString("scrawlPathFormat") + "root/{yyyy}_{mm}/{time}{rand:6}",
                        SizeLimit = UEConfig.GetInt("scrawlMaxSize"),
                        UploadFieldName = UEConfig.GetString("scrawlFieldName"),
                        Base64 = true,
                        Base64Filename = "scrawl.png"
                    });
                    break;
                case "uploadvideo":
                    action = new UploadHandler(context, new UploadConfig()
                    {
                        AllowExtensions = UEConfig.GetStringList("videoAllowFiles"),
                        PathFormat = UEConfig.GetString("videoPathFormat") + "root/{yyyy}_{mm}/{time}{rand:6}",
                        SizeLimit = UEConfig.GetInt("videoMaxSize"),
                        UploadFieldName = UEConfig.GetString("videoFieldName")
                    });
                    break;
                case "uploadfile":
                    action = new UploadHandler(context, new UploadConfig()
                    {
                        AllowExtensions = UEConfig.GetStringList("fileAllowFiles"),
                        PathFormat = UEConfig.GetString("filePathFormat") + "root/{yyyy}_{mm}/{time}{rand:6}",
                        SizeLimit = UEConfig.GetInt("fileMaxSize"),
                        UploadFieldName = UEConfig.GetString("fileFieldName")
                    });
                    break;
                case "listimage":
                    action = new ListFileManager(context, UEConfig.GetString("imageManagerListPath") + "root", UEConfig.GetStringList("imageManagerAllowFiles"));
                    break;
                case "listfile":
                    action = new ListFileManager(context, UEConfig.GetString("fileManagerListPath") + "root", UEConfig.GetStringList("fileManagerAllowFiles"));
                    break;
                case "catchimage":
                    action = new CrawlerHandler(context);
                    break;
                default:
                    action = new NotSupportedHandler(context);
                    break;
            }
            action.Process();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }   
